#include <cstdlib>
#include <ctime>

#include <eq/eq.h>

#include "appfactory.h"

int main(int argc, char **argv)
{
    eqtest::AppFactory factory;
    
    eq::init(argc, argv, &factory);
    
    eq::Config *config = eq::getConfig(argc, argv);
    
    config->init(0);
    
    uint64_t frameCounter = 0;
    std::time_t start = std::time(0);
    while(config->isRunning())
    {
       config->startFrame(0);
        config->finishFrame();
        ++frameCounter;
    }
    std::time_t end = std::time(0);
    
    double diff = std::difftime(end, start);
    
    std::cout << "Frames finished: " << frameCounter << std::endl;
    std::cout << "Time elapsed   : " << diff << " (1)" << std::endl;
    std::cout << "Estimated FPS  : " << frameCounter / (diff + 1) << " - " << frameCounter / (diff - 1) <<std::endl;
    std::cout << "Estimated ms/f : " <<
    (diff - 1) * 1000 / frameCounter << ", " <<
    diff * 1000 / frameCounter << ", " <<
    (diff + 1) * 1000 / frameCounter << std::endl;
    
    config->exit();
    
    eq::releaseConfig(config);
    
    eq::exit();
    
    return 0;
}
